//
//  CMDBAssociateFooterView.swift
//  CMDB
//
//  Created by 王磊 on 09/05/2017.
//  Copyright © 2017 CMDB. All rights reserved.
//

import UIKit

protocol CMDBAssociateFooterViewDelegate: NSObjectProtocol {
    
    func associateWorks()
}

class CMDBAssociateFooterView: UICollectionReusableView {
    
    private var associateBtn: UIButton = UIButton(type: .Custom)
    
    weak var associateDelegate: CMDBAssociateFooterViewDelegate?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        configOwnSubviews()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
extension CMDBAssociateFooterView {
    
    override func configOwnSubviews() {
        
        addSubview(associateBtn)
        
        associateBtn.setTitle("确认关联", forState: .Normal)
        associateBtn.setTitle("确认关联", forState: .Highlighted)
        
        associateBtn.setTitleColor(UIColor.Hex6(0xffffff, alpha: 0.54), forState: .Highlighted)
        
        associateBtn.setTitleColor(UIColor.Hex6(0xffffff), forState: .Normal)
        
        associateBtn.backgroundColor = UIColor.Hex6(0xff6d00, alpha: 54)
        
        associateBtn.titleLabel!.font = CMDB_17_FONT
        
        associateBtn.addTarget(self, action: #selector(associate), forControlEvents: .TouchUpInside)
        
        associateBtn.layer.cornerRadius = 5
    }
}
extension CMDBAssociateFooterView {
    
    @objc private func associate() {
        
        guard let delegate = associateDelegate else {
            
            return
        }
        delegate.associateWorks()
    }
}

extension CMDBAssociateFooterView {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        associateBtn.snp_makeConstraints { (make) in
            
            make.left.equalTo(Associate_Section_Inset_Margin)
            
            make.right.equalTo(-Associate_Section_Inset_Margin)
            
            make.centerY.equalTo(0)
            
            make.height.equalTo(88 * CMDB_Rate)
        }
    }
}